package 刷题.leedcode22;
//快慢指针法
//OJ大佬
public class Solution3 {
    public ListNode FindKthToTail(ListNode head,int k){
        if(head == null){
            return null;
        }
        ListNode pre = head;//前指针
        ListNode cur = head;
        //排除了k过大导致越界
        while(pre != null && (k--) != 0){
            pre = pre.next;
        }
        if(pre == null && k != 0){
            return null;
        }
        while(pre != null){
            pre = pre.next;
            cur = cur.next;
        }
        return cur;
    }
}
